function getUserInfo(page) {
    $.ajax({
        type: 'get',
        url: 'login',
        success: function (body) {
            // 判断 body是否有效
            if (body.userId && body.userId > 0){
                if (page == 'list.html'){
                    getMessage(body.userName);
                    console.log("用户"+body.userName+"登录成功")
                }
            }else {
                // 跳到 login.html
                alert("当前您尚未登录,请先登录!")
                location.assign('login.html')
            }
        },
        error:function () {
            alert("当前网络连接错误 请重试!")
            location.assign('login.html')
        }
    })
}

// // 左侧内容更新
// // 获取左侧用户信息,根据用户名得到用户信息
function getMessage(userName) {
    let name = document.querySelector("#name");
    let picture = document.querySelector("#picture");
    let github = document.querySelector("#github");
    $.ajax({
        type: 'get',
        url: 'user' + '?photo=yes',
        contentType: 'application/json',
        success: function (body) {
            name.innerHTML = body.userName;
            picture.src = "./image/" + body.photo + ".png";
            if (body.github && body.github != '' && body.github != 'NULL'){
                github.href = body.github;
            }else{
                github.innerHTML = '';
            }
        }
    })

    // // 获取个人主页
    let count = document.querySelector("#count");
    $.ajax({
        type: 'get',
        url: 'user' + "?count=yes",
        success: function (body) {
            count.innerHTML = body.length;
        }
    })
}